package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanhua.domain.BlackList;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 黑名单服务提供者
 */
@DubboService
public class BlackListApiImpl extends ServiceImpl<BlackListMapper, BlackList> implements BlackListApi {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 移除黑名单
     * @param userId
     * @param uid
     */
    @Override
    public void removeBlackList(Long userId, Long uid) {
        LambdaQueryWrapper<BlackList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BlackList::getUserId,userId);
        wrapper.eq(BlackList::getBlackUserId,uid);
        blackListMapper.delete(wrapper);
    }

    /**
     * 黑名单分页方法
     * @param userId
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage blackList(Long userId, int page, int size) {
        //1、构建分页参数对象Page(MyBatis需要的内置page参数)
        Page pages = new Page(page, size);
        //2、调用方法分页（自定义编写 分页参数Page，sql条件参数）
        return userInfoMapper.findBlackList(pages, userId);
    }
}
